package com.nuorui.module.system.controller;

import com.nuorui.common.constant.AdminSwaggerTagConst;
import com.nuorui.common.core.domain.ResponseDTO;
import com.nuorui.module.system.domain.form.RoleUserForm;
import com.nuorui.module.system.domain.vo.UserVO;
import com.nuorui.module.system.service.RoleUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

import javax.validation.constraints.NotEmpty;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Set;

/**
 * 角色管理
 *
 * @author: Fred
 * @email 453086@qq.com
 * @create: 2021-10-22 10:42
 */
@RestController
@RequiredArgsConstructor
@Api(tags = AdminSwaggerTagConst.System.SYSTEM_ROLE_USER)
public class RoleUserController {

    private final RoleUserService roleUserService;

    @GetMapping("/roles/{roleId}/users")
    @ApiOperation(value = "查询角色下的员工列表", notes = "查询角色下的员工列表")
    public ResponseDTO<List<UserVO>> getUsersByRoleId(@PathVariable("roleId") Long roleId) {
        return roleUserService.getUsersByRoleId(roleId);
    }

    @PostMapping("/roles/{roleId}/users")
    @ApiOperation(value = "为指定角色批量添加用户", notes = "批量新增角色下的用户")
    public ResponseDTO<String> saveBatch(@PathVariable("roleId") Long roleId, @Valid @RequestBody RoleUserForm roleUserForm) {
        return roleUserService.batchSave(roleId, roleUserForm);
    }
}
